package servlet;
import java.io.IOException;
import java.io.OutputStream;
import java.io.InputStream;

import javax.servlet.*;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;



/**
 *  ����ʵ���ˣ���ͻ��˷��ͷ�HTML���ݵ�Servlet��CodeReturn.java�����з��͵�jar�ļ�Ϊ��bookCode.jar
 * @author QZK
 * @version 1.0
 */
@WebServlet("/DocReturn")
public class DocReturn extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public DocReturn() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * achieve the function
	 * @param request 
	 * the request send by the client to the server 
	 * @param response 
	 * the response send by the server to the client 
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		//设置相应类型为jar文件
		response.setContentType("application/msword");
		ServletContext ctx = getServletContext();
		//设置一个输入流来获取bookCode.jar文件
		InputStream is = (InputStream) ctx.getResourceAsStream("/系统使用说明书.docx");
		//设置一个计数器
		int read = 0;
		//设置一个缓冲区
		byte[] bytes = new byte[1024];
		OutputStream os = response.getOutputStream(); 
		//循环读出内阁字节
		while( (read=is.read(bytes))!=-1 ) {
			os.write(bytes,0,read);
		} 
		os.flush();
		os.close();
		request.getRequestDispatcher("Index_Date").forward(request, response);
	}
}
